package com.stox.charting.ui.swing.event.listener;

import com.stox.charting.ui.swing.event.ChartModelChangedEvent;
import com.stox.charting.ui.swing.model.BarSpan;
import com.stox.charting.ui.swing.model.ChartModel.ChartModelListener;
import com.stox.charting.ui.swing.model.price.PriceChartModel;
import com.stox.charting.ui.swing.widget.BarSpanComboBox;
import com.stox.core.model.IBar;
import com.stox.ioc.Container;

public class MinimumSpanDataChangedEventListender implements ChartModelListener {

	@Override
	@SuppressWarnings("unchecked")
	public void chartModelChanged(ChartModelChangedEvent event) {
		if(event.getProperty().equalsIgnoreCase("minimumSpanData")){
			PriceChartModel<? extends IBar> priceChartModel = (PriceChartModel<? extends IBar>)event.getSource();
			BarSpanComboBox barSpanComboBox = Container.get(BarSpanComboBox.class);
			
			priceChartModel.setEventsEnabled(false);
			priceChartModel.setBarSpan((BarSpan)barSpanComboBox.getItemAt(barSpanComboBox.getSelectedIndex()));
			priceChartModel.setEventsEnabled(true);
			priceChartModel.fireChartModelChangedEvent("barSpan");
		}
	}

}
